package share.download.utils;


public class SingleThreadSpeedLimiter {
	long SpeedLimit = 64 * 1024;
	long BytesDownloaded = 0;
	long StartTime = 0;

	public SingleThreadSpeedLimiter() {
		StartTime = System.currentTimeMillis();
	}

	public void registerNewBytes(long BytesCount) {
		BytesDownloaded += BytesCount;
	}

	public boolean allowDownload() {
		if (System.currentTimeMillis() == StartTime)
			return true;
		try {
			if (BytesDownloaded * 1000 >= SpeedLimit
					* (System.currentTimeMillis() - StartTime))
				return false;
		} catch (Exception e) {
			e.printStackTrace();
			return true;
		}
		return true;
	}
}